package Dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import Dao.Daomcthree;
import entity.mcthree;
import utils.BaseDao;

public class Daoimplmcthree extends BaseDao implements Daomcthree {

	@Override
	public List<mcthree> mcthteelist() {
		String sql = "select * from mcthree";
		ResultSet set = super.executeQuery(sql, null);
		List<mcthree> list = new ArrayList<mcthree>();
		try {
			while(set.next()){
				list.add(new mcthree(set.getInt(1),set.getString(2),set.getString(3),set.getInt(4)));
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			super.closeAll(set, null, null);
		}
		return list;
	}

	@Override
	public List<mcthree> mcthteelist(int spid) {
		String sql = "select * from mcthree where spid = ?";
		Object[] object = {spid};
		ResultSet set = super.executeQuery(sql, object);
		List<mcthree> list = new ArrayList<mcthree>();
		try {
			while(set.next()){
				list.add(new mcthree(set.getInt(1),set.getString(2),set.getString(3),set.getInt(4)));
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			super.closeAll(set, null, null);
		}
		return list;
	}

	@Override
	public boolean add(mcthree mcthree) {
		String sql = "insert into `project`.`mcthree` (`name`, `img`, `spid`) values (?,?,?)";
		Object[] object = {mcthree.getName(),mcthree.getImg(),mcthree.getSpid()};
		return super.executeUpdate(sql, object);
	}

	@Override
	public boolean del(int id) {
		String sql = "delete from `project`.`mcthree` where `id` = ?";
		Object[] object = {id};
		return super.executeUpdate(sql, object);
	}

}
